package course.p5_stack;

import org.junit.Assert;
import org.junit.Test;

import java.util.Optional;
import java.util.Random;
import java.util.Stack;

public class StackTest {

    private final Stack<Integer> stackRight = new Stack<>();

    @Test
    public void stackTest(){
        ArrayStack stack = new ArrayStack();
        for (int i=0;i<1000;i++){
            boolean active = new Random().nextBoolean();
            if(active){
                stack.push(i);
                stackRight.push(i);
            }else {
                Assert.assertEquals(stackRight.isEmpty(),stack.isEmpty());
                if(!stackRight.isEmpty()){
                    Assert.assertEquals(Optional.ofNullable(stackRight.pop()),Optional.ofNullable(stack.pop()));
                }
            }
        }
    }

}
